package com.kevin.netty.protocol.protobuf.util;

import com.kevin.netty.protocol.protobuf.BasicMessage;

public class ProtobufMessageUtil {

    /**
     * 模拟数据
     */
    public static BasicMessage.Basic protobufMock() {
        String payload = "Hello world protobuf";
        return BasicMessage.Basic.newBuilder()
                .setHeadString("$$")
                .setRequestType(BasicMessage.RequestType.NOTICE)
                .setResponseType(BasicMessage.ResponseType.SUCCESS)
                .setPayload(payload).setPayloadLength(payload.length()).build();
    }

    /**
     * 序列化
     *
     * @param basicMessage 基础消息
     * @return byte[]
     */
    public static byte[] serializer(BasicMessage.Basic basicMessage) {
        return basicMessage.toByteArray();
    }

}
